// pages/school/detail/index.js
const {
  schoolDetail,
  schoolAdd,
  scoreProvince,
  scoreSpecial,
  specialHistory,
  employmentunit,
  employmentunittype,
  signedplace,
  openmajor,
  provinceCategory,
  specialCategory,
  specialBatch,
  specialSpcgroup,
  schoolNewsPage,
  schoolNews,
  schoolBranch,
  schoolBranchDetail,
  planBatch,
  planCategory,
  planSpcgroup,
  planPage,
  planHistory,
  samescoreList,
  schoolJoList,
  shareAdd,
  shareDeduct
} = require('../../../api/api')
const {
  returnLabel,checkLogin
} = require('../../../utils/util')
var  two=''
const {
  planVoluntaryPage,
} = require('../../../api/ai')
import * as echarts from '../../../components/ec-canvas/echarts.min';
// 暂不引用
// const city = require('../js/city')
// 招生计划筛选条件
const planRouteDatas = [{
    id: 0,
    title: "全国",
    type: "radiobox",
    key: "provinceId",
    items: []
  },
  {
    id: 1,
    title: 2023,
    key: "year",
    type: "radiobox",
    items: []
  },
  {
    id: 2,
    title: "综合类",
    key: "type",
    type: "radiobox",
    items: []
  },
  {
    id: 3,
    title: "本科批",
    key: "localBatchName",
    type: 'radiobox',
    items: [],
  },
  {
    id: 4,
    title: "全部",
    key: "sgName",
    type: 'radiobox',
    items: []
  },
]
// 历史分数线筛选条件
const historyRouteDatas = [{
    id: 0,
    title: "全国",
    type: "radiobox",
    key: "provinceId",
    items: []
  },
  {
    id: 1,
    title: 2022,
    key: "year",
    type: "radiobox",
    items: []
  },
  {
    id: 2,
    title: "综合类",
    key: "type",
    type: "radiobox",
    items: []
  },
]
//  专业分数线筛选条件
const selectedRouteDatas = [{
    id: 0,
    title: "全国",
    type: "radiobox",
    key: "provinceId",
    items: []
  },
  {
    id: 1,
    title: 2021,
    key: "year",
    type: "radiobox",
    items: []
  },
  {
    id: 2,
    title: "综合类",
    key: "type",
    type: "radiobox",
    items: []
  },
  {
    id: 3,
    title: "本科批",
    key: "batch",
    type: 'radiobox',
    items: [],
  },
  {
    id: 4,
    title: "全部",
    key: "sgName",
    type: 'radiobox',
    items: []
  },
]

function pieChartSel(charts) {
  const that = this;
  let index = 0;
  //默认选中
  charts.dispatchAction({
    type: 'highlight',
    seriesIndex: 0,
    dataIndex: 0,
  });

  //hover选中
  charts.on('mouseover', function (e) {
    if (e.dataIndex != index) {
      charts.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: index,
      });
    }
  });
  charts.on('mouseout', function (e) {
    index = e.dataIndex;
    charts.dispatchAction({
      type: 'highlight',
      seriesIndex: 0,
      dataIndex: e.dataIndex,
    });
  });

  //点击选中
  charts.on("click", function (e) {
    if (e.dataIndex != index) {
      charts.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: index,
      });
    }
    index = e.dataIndex;
    charts.dispatchAction({
      type: 'highlight',
      seriesIndex: 0,
      dataIndex: e.dataIndex,
    });
  });
}
const color = ['#82cd00', '#ff9100', '#ffd000', '#ec4724', '#524fe5', '#a4baff', '#cc7cbd', '#52b0ac', '#f4baac']
// 签约流向饼图
function setPieoption(chart, data) {
  // data.sort((a, b) => b.value - a.value)
  const option = {
    color: color,
    tooltip: {
      show: false
    },
    // legend: {
    //   top: '220',
    //   left: 8,
    //   data: data,
    //   itemWidth: 10,
    //   itemHeight: 10,
    //   itemGap: 20,
    //   show: true,
    //   icon: 'rect',
    //   selectedMode: false,
    //   formatter: function (name) {
    //     let tarValue
    //     for (let i = 0; i < data.length; i++) {
    //       if (data[i].name == name) {
    //         tarValue = data[i].value
    //       }
    //     }
    //     let p
    //     if (tarValue < 10) {
    //       p = tarValue + '%  '
    //     } else {
    //       p = tarValue + '%'
    //     }
    //     return `{a|${p}}\n{b|${name}}`
    //   },
    //   textStyle: {
    //     lineHeight: 14,
    //     rich: {
    //       a: {
    //         fontSize: 14,
    //       },
    //       b: {
    //         fontSize: 10
    //       },
    //     },
    //     padding: [14, 0, -2, 0], //[上、右、下、左]
    //   },
    // },
    series: [{
      name: 'Access From',
      type: 'pie',
      radius: ['56%', '76%'],
      center: ['50%', '52%'],
      avoidLabelOverlap: false,
      label: {
        show: false,
        position: 'center',
      },
      emphasis: {
        label: {
          show: true,
          fontSize: '20',
          fontWeight: '500',
          color: '#000',
          formatter: '{a|{d}%\n}{b|{b}}',
          padding: [10, 10],
          rich: {
            a: {
              fontSize: 20
            },
            b: {
              fontSize: 14
            }
          }
        }
      },
      labelLine: {
        show: false
      },

      data: data
    }]
  };
  chart.setOption(option);
  pieChartSel(chart)
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin:true,
    colorList:['#FCA400','#29BC00','#334EFF'],
    progressShow:false,
    status:false,
    schoolShow:false,
    loading:true,
    isVip: false,
    isSvip: false,
    seeMore: false,
    ellipsis: true,
    typeVip: 'vip',
    joList: [],
    color: color,
    details: {},
    tabData3: [],
    tabData5: [],
    majorList: [],
    videoShow: 1,
    picList: [],
    id: 1,
    pageSize: 10,
    pageNo: 1,
    pageENo: 1,
    data: [],
    bottomLift: getApp().globalData.bottomLift,
    tabList: ['概况', '分数', '计划', '就业', '录取概率'],
    schoolList: [],
    admitList: [],
    currentIndex: 0,
    branchList: {},
    branchTotal: 0, //分校+院系总数量
    luquListTotal: 0,
    filterRouteKey: "schoolDetailFilters",
    selectedRouteData: {
      provinceId: 0,
      year: '2021',
      type: '物理类',
      batch: 1,
      sgName: ''
    },
    selectedRouteDatas: selectedRouteDatas,
    historyRouteKey: "historyFilters",
    historyRouteData: {
      provinceId: 0,
      year: '2021',
      type: '物理类',
    },
    historyRouteDatas: historyRouteDatas,
    // 招生计划筛选
    planRouteKey: "planFilters",
    planRouteData: {
      provinceId: 0,
      year: '2021',
      type: '物理类',
      localBatchName: '',
      sgName: ''
    },
    planRouteDatas: planRouteDatas,
    tabData1: [],
    tabData: [],
    list1: [],
    // 历史分数线 表头
    columns: [{
        label: '批次',
        prop: 'localBatchName',
        fontSize: '',
        width: '150',
        align: 'center',
      },
      {
        label: '招生类型',
        prop: 'zslxName',
        align: 'center',
        width: '150'
      },
      {
        label: '专业组/选科',
        prop: 'sgName',
        scopedSlots: 'scoped',
        extra: 'sgInfo',
        align: 'center',
        width: 180,
        padding: '20rpx',
        colspan: ['sgName', 'sgInfo']

      },
      {
        label: '最低分/位次',
        prop: 'min',
        width: 170,
        type: 'customRender',
        param: 'minSection',
        align: 'center',
        isFilter: true
      },
    ],
    columnsList: [],
    columns5: [{
        label: '专业名称',
        prop: 'sptitle',
        fontSize: '',
        width: 258,
        seeMore:true,
        align: 'center'
      },
      {
        label: '选科',
        prop: 'sgInfo',
        align: 'center',
        width: 86,
      },
      {
        label: '学制/学费',
        prop: 'length',
        width: 86,
        scopedSlots: 'scoped',
        extra: 'tuition',
        align: 'center',
        padding: '20rpx',
        colspan: ['length', 'tuition'],
        isFilter: true
      },
      {
        label: '招生人数',
        prop: 'num',
        width: 86,
        align: 'center',
        isFilter: true
      },
      {
        label: '专业组',
        prop: 'sgCode',
        width: 86,
        align: 'center',
        isFilter: true
      },
      // {
      //   label: '备注',
      //   prop: 'remark',
      //   width: 86,
      //   align: 'center',
      // },

    ],
    columns1: [{
        label: '专业名称',
        prop: 'sptitle',
        seeMore:true,
        fontSize: '',
        width: 200,
        align: 'center'
      },
      {
        label: '选科',
        prop: 'sgInfo',
        align: 'center',
        width: 100
      },
      {
        label: '平均分',
        prop: 'average',
        width: 100,
        align: 'center',
        isFilter: true
      },
      {
        label: '专业组',
        prop: 'sgCode',
        width: 100,
        align: 'center',
      },
      // {
      //   label: '备注',
      //   prop: 'remark',
      //   width: 100,
      //   align: 'center',
      // },
      {
        label: '最低分/位次',
        prop: 'min',
        width: 150,
        type: 'customRender',
        param: 'minSection',
        align: 'center',
        isFilter: true
      },
    ],
    columns3: [{
        label: '签约单位',
        prop: 'companyname',
        fontSize: '',
        width: 550,
      },
      {
        label: '人数',
        prop: 'numberofpeople',
        width: 100,
        align: 'center',
        isFilter: true
      },
    ],
    majorSetting: {
      theadHeight: '110rpx', // 表头的高度
    },
    setting: {
      tableOutBorder: 'none', // 表格外边框
      tableInBorder: 'none', // 表格内边框
      tableInBorderLevel: true, // 表格内只显示水平边框
      theadFontSize: '28', // 表头的字体大小
      tbodyFontSize: '28', // 表格行的字体大小
      trHeight: 92, // 表格行 tr 的高度
      stripeHeight: '74',
      stripeColor: '#f2f2f2'
    },
    ec: {
      lazyLoad: true,
    },
    aSchoolSpecialtyVoList: [],
    userCitys: {},
    showMore: false,
    isASpecialTrue: false,
    planHistoryTrue:false,
    isReportTrue: false,
    isMajorTrue: false,
    isSchoolTrue: false,
    canvasHeight: 784,
    show:false,
    luquList: [
      //   {
      //   statusCode: 'nan',
      //   statusName: '难',
      //   ratio: '<10%'
      // }, {
      //   statusCode: 'chong',
      //   statusName: '冲',
      //   ratio: '35%'
      // }, {
      //   statusCode: 'bao',
      //   statusName: '保'
      // }
    ],
    pieData: [],
    currentIndexArray: [1, 0, 0, 0, 0],
    visible: false,
    volunteerShow:false,
    provinceDesc:wx.getStorageSync('provinceDesc'),
    TabCur: 0,
    MainCur: 0,
    VerticalNavTop: 0,
    TabCurList:[
      {
        name:'数学',
        id:0
      },{
        name:'数学与应用数学',
        id:1
      },{
        name:'小学教育',
        id:2
      },{
        name:'学前教育',
        id:3
      },{
        name:'数学与应用数学',
        id:4
      },{
        name:'数学与应用数学',
        id:5
      },{
        name:'数学与应用数学',
        id:6
      }
    ]
  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50
    })
  },
  downt(){
    const {TabCur,TabCurList}=this.data
    this.setData({
      // TabCur:TabCurList.length-1,
      VerticalNavTop: (TabCurList.length - 1) * 50
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  showMore(e) {
    const {
      type
    } = e.currentTarget.dataset
    this.setData({
      [type]: !this.data[type]
    })
  },
  contact(){
    getApp().getCustomerService()
},
  dialogClose(e) {
    const {type}=e.currentTarget.dataset
    this.setData({
      [type]: false
    })
  },
   onLoad: function (options) {
    if(options.spreadUserId){
        shareAdd({spreadUserId: options.spreadUserId}).then(res=>{})
    }
    if (options.id) {
      this.setData({
        id: options.id
      })
      this.getDetail()
      this.getOpenmajor()
      this.getSchoolBranch()
    }
    if (options.name) {
      wx.setNavigationBarTitle({
        title: options.name,
      })
    }
    const {
      filterRouteKey,
      selectedRouteData,
      historyRouteKey,
      historyRouteData,
      planRouteData,
      planRouteKey
    } = this.data
    const {
      code
    } = wx.getStorageSync('userCitys')
    selectedRouteData.provinceId = code
    historyRouteData.provinceId = code
    planRouteData.provinceId = code
    this.setData({
      userCitys: wx.getStorageSync('userCitys'),
      selectedRouteData,
      historyRouteData,
      planRouteData
    })
    wx.setStorageSync(filterRouteKey, selectedRouteData)
    wx.setStorageSync(historyRouteKey, historyRouteData)
    wx.setStorageSync(planRouteKey, planRouteData)
    this.fetchCity()
  },
  getToday() {
    let that = this
    wx.getStorage({
      key: 'todays',
      success: function (res) {
        if (res.data && res.data != new Date().toLocaleDateString()) {
          wx.setStorageSync("todays", new Date().toLocaleDateString());
          that.setData({
            volunteerShow:true
          })
        }
      },
      fail: function (res) {
        wx.setStorageSync("todays", new Date().toLocaleDateString());
        that.setData({
          volunteerShow:true
        })
      }
    })
  },
  onShow() {
    this.fetchUserInfo()
  },
  async markShow(e){
    const {type,name}=e.currentTarget.dataset
    const {enableCount,shareDate,shareCount}= await getApp().fetchUserInfo()
     let shareShow =new Date().toLocaleDateString()!=new Date(shareDate).toLocaleDateString()
      this.setData({
        shareShow,
        enableCount,
        shareCount
      })
    wx.showModal({
      title: '提示',
      content: '是否消耗体验次数查看',
      complete: async (res) => {
        if (res.confirm) {
          if(!enableCount){
            this.setData({
              show:true
            })
            return
          }
         await shareDeduct({})
         if(name){
            const data=this.data[type]
            data[e.detail].isFilter=false
              this.setData({
                [type]:data
              })
            return
         }
          this.setData({
            [type]:true
          })
        }
      }
    })
  
  },
  async fetchUserInfo() {
    const {vipType,shareCount,enableCount,shareDate}= await getApp().fetchUserInfo()
    let shareShow =new Date().toLocaleDateString()!=new Date(shareDate).toLocaleDateString()
    // let volunteerShow=vipType=='svip'?false:true
    this.setData({
       isVip:vipType,
       shareCount,
       enableCount,
      //  volunteerShow,
       show:shareShow && !vipType?true:false,
       shareShow,
       isSvip:vipType=='svip'?vipType : false,
       typeVip: vipType=='vip' ? 'svip' : 'vip'
   })
   if(vipType!='svip'){
    //  this.getToday()
   }
  },
 async receive(){
      await shareAdd({})
      this.setData({
        show:false
      })
  },
  // 学校就业质量报告
  async schoolJoList() {
    const {
      id,
      joList
    } = this.data
    if (joList.length > 0) return
    const {
      result
    } = await schoolJoList(id)
    this.setData({
      joList: result
    })
  },
  // 招生信息详情
  async detail(e) {
    const {
      id,
    } = e.currentTarget.dataset
    if (id == undefined) return
    const {
      result
    } = await schoolNews(id)
    wx.navigateTo({
      url: `/pages/article/rich-text/index?content=` + encodeURIComponent(result.content) + '&name=' + result.title + '&type=parse',
    })
  },
  async fetchCity() {
    const {
      type,
      historyRouteDatas,
      selectedRouteDatas,
      selectedRouteData,
      historyRouteData,
      planRouteData,
      planRouteDatas
    } = this.data
    const items = wx.getStorageSync('cityList') || await getApp().getCityList()
    items.forEach(e => {
      if (e.id == historyRouteData.provinceId) {
        historyRouteDatas[0].title = e.title
        selectedRouteDatas[0].title = e.title
        planRouteDatas[0].title = e.title
      }
    })
    historyRouteDatas[0].items = items
    selectedRouteDatas[0].items = items
    planRouteDatas[0].items = items
    this.setData({
      historyRouteDatas,
      selectedRouteDatas,
      planRouteDatas
    })
  },


  // 获取各省历史分数线
  async onSelectChangedRoute1(e) {
    const {
      historyRouteKey
    } = this.data
    wx.setStorageSync(historyRouteKey, {
      ...e.detail
    });
    this.setData({
       tabData:[]
    })
    this.selectComponent("#tabData1").show()
    this.filterKeyFunc()
  },
  filterKeyFunc() {
    const {
      historyRouteKey
    } = this.data
    const historyRouteData = wx.getStorageSync(historyRouteKey)
    const {
      historyRouteDatas,
      data,
    } = this.data
    if (historyRouteData['provinceId'] !== this.data.historyRouteData['provinceId']) {
      this.setData({
        historyRouteData
      })
      wx.setStorageSync(historyRouteKey, historyRouteData)
      this.getProvinceScore()
      return
    }
    var list = []
    data.map((item) => {
      if (item.year == historyRouteData['year']) {
        list = item.list
        if (historyRouteData['year'] !== this.data.historyRouteData['year']) {
          historyRouteData['type'] = list[0].id
          const firstSelectSubjects=wx.getStorageSync('subjectInfo').firstSelectSubjects || ''
            if(firstSelectSubjects){
              list.map(e=>{
                if(e.id.indexOf(firstSelectSubjects)>-1){
                  historyRouteData['type']=e.id
                }
              })
            }
          wx.setStorageSync(historyRouteKey, historyRouteData)
        }
      }
    })
    historyRouteDatas[2].items = list
    historyRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == historyRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : item.title
    })
    this.setData({
      historyRouteData,
      historyRouteDatas
    })
    this.getScoreProvince(historyRouteData)
    this.getSamescoreList()
  },
  // 获取各省历史分数线
  async getProvinceScore() {
    const {
      historyRouteData,
      historyRouteKey,
      historyRouteDatas,
      id
    } = this.data
    const params = {
      schoolId: id,
      provinceId: historyRouteData.provinceId
    }
    const {
      result
    } = await provinceCategory(params,two)
    if (result.length > 0) {
      result.sort((a, b) => {
        return b.year - a.year
      }) //倒序
      result.map((item) => {
        item.list=item.list.reverse()
        item.list.map((e, i) => {
          let obj = {
            id: e,
            title: e
          }
          item.list[i] = obj
        })
      })
      var yearArr = result.map((item) => {
        return {
          id: item.year,
          title: item.year
        }
      })
      const {
        list
      } = result[0]
      historyRouteData.year = yearArr[0].id
      historyRouteData.type = list[0].id
      const firstSelectSubjects=wx.getStorageSync('subjectInfo').firstSelectSubjects || ''
      if(firstSelectSubjects){
        list.map(e=>{
          if(e.id.indexOf(firstSelectSubjects)>-1){
            historyRouteData['type']=e.id
          }
        })
      }
      historyRouteDatas[1].items = yearArr
      historyRouteDatas[2].items = list
    }
    historyRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == historyRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : item.title
    })
    this.setData({
      historyRouteData,
      historyRouteDatas
    })
    wx.setStorageSync(historyRouteKey, historyRouteData)
    this.setData({
      data: result,
    })
    this.getScoreProvince(historyRouteData)
    this.getSamescoreList()
  },
  async getScoreProvince(selectData) {
    selectData.schoolId = this.data.id
    const {
      columns
    } = this.data
    const {
      result
    } = await scoreProvince(selectData,two)
    let columnsList = []
    if (result.length > 0) {
      columnsList = columns.filter((e) => {
        return result[0][e.prop]
      })
    } else {
      columnsList = columns
    }
    // columnsList.map((e) => {
      // e.width = 650 / columnsList.length
    // })
    this.setData({
      tabData: result,
      columnsList,
    })
    this.selectComponent("#tabData1").hide('本省今年未发布该校分数信息')
  },

  changeIndex(e) {
    const {
      index,
    } = e.currentTarget.dataset
    const {
      currentIndexArray,
      currentIndex,
      id,
      tabData,
      tabData1,
      tabData5,
      admitList
    } = this.data
    if (index == currentIndex) return
    this.setData({
      currentIndex: parseInt(index),
    })
    if (currentIndexArray[parseInt(index)] > 0) return //返回值为空也不加载数据
    if (index == 1) {
      // if (tabData.length > 0 && tabData1.length > 0) return
      this.getProvinceScore()
      this.getSpecialCategory()
    } else if (index == 2) {
      // if (tabData5.length > 0 && admitList.length > 0) return
      this.getSchoolNewsPage()
      this.getPlanList()
    } else if (index == 3) {
      this.schoolJoList()
      this.initChart();
      this.getEmploymentunittype(id)
      this.getEmploymentunit(id)
    } else {
      checkLogin().then(res=>{
        this.getEnrollmentList()
        this.setData({
          isLogin:true
        })
      }).catch(e=>{
        this.setData({
          isLogin:false
        })
      })
    }
    currentIndexArray[parseInt(index)] += 1
    this.setData({
      currentIndexArray
    })
  },
  //  获取学校-录取概率
  async getEnrollmentList() {
    let {
      id,
      pageSize,
      pageENo,
      isVip,
      luquList
    } = this.data
    const params = {
      active: 'all',
      schoolId: id,
      // pageNo: pageENo,
      // pageSize: isVip ? pageSize : 3,
      showAll:true,
    }
    const {
      result
    } = await planVoluntaryPage(params)
    if (isVip && pageENo == 1) {
        luquList = []
    }
    this.setData({
      // luquList: luquList.concat(result.records),
      luquList: isVip?result.records:result.records.slice(0,3),
      pageENo: pageENo + 1,
      luquListTotal: result.total,
    })
    if (result.total > 0) {
      var luquRatio = this.data.luquList[0].matchRate
      // if (luquRatio >= 0.66) {
        luquRatio = `` +(parseInt(Math.round(luquRatio*100)))+`%`
      // } else if (luquRatio >= 0.49) {
      //   luquRatio = '&lt;66%'
      // } else if (luquRatio >= 0.1) {
      //   luquRatio = '&lt;49%'
      // } else {
      //   luquRatio = '&lt;10%'
      // }
      this.setData({
        luquRatio,
        loading:false
      })
    } else {
      this.setData({
        luquRatio: "&lt;10%",
        loading:false
      })
    }
  },
  update(e) {
    this.setData({
      pageENo: 1,
      luquList: []
    })
    this.getEnrollmentList()
  },
  async getSamescoreList() {
    const {
      historyRouteData,
      details
    } = this.data
    const params = {
      schoolId: details.id,
      provinceId: historyRouteData.provinceId,
      year: historyRouteData.year,
      type: historyRouteData.type,
    }
    const {
      result
    } = await samescoreList(params)
    this.setData({
      schoolList: result,
    })
  },
  // 获取专业分数线
  async onSelectChangedRoute(e) {
    const {
      filterRouteKey
    } = this.data
    wx.setStorageSync(filterRouteKey, {
      ...e.detail,
    });
    this.setData({
      tabData1:[]
    })
    this.selectComponent("#tabData2").show()
    this.filterKeyFunc1()
  },
  filterKeyFunc1() {
    const {
      filterRouteKey
    } = this.data
    const selectedRouteData = wx.getStorageSync(filterRouteKey)
    const {
      selectedRouteDatas,
      categorydata,
      batchData,
      spcgroupData
    } = this.data
    if (selectedRouteData['provinceId'] !== this.data.selectedRouteData['provinceId']) {
      this.setData({
        selectedRouteData
      })
      wx.setStorageSync(filterRouteKey, selectedRouteData)
      this.getSpecialCategory()
      return
    }
    if (selectedRouteData['type'] !== this.data.selectedRouteData['type']) {
      this.setData({
        selectedRouteData
      })
      wx.setStorageSync(filterRouteKey, selectedRouteData)
      this.getSpecialSpcgroup()
      return
    }
    var list = []
    categorydata.map((item) => {
      if (item.year == selectedRouteData['year']) {
        list = item.list
        if (selectedRouteData['year'] !== this.data.selectedRouteData['year']) {
          selectedRouteData['type'] = list[0].id
          const firstSelectSubjects=wx.getStorageSync('subjectInfo').firstSelectSubjects || ''
          if(firstSelectSubjects){
            list.map(e=>{
              if(e.id.indexOf(firstSelectSubjects)>-1){
                 selectedRouteData['type']=e.id
              }
            })
          }
          wx.setStorageSync(filterRouteKey, selectedRouteData)
        }
      }
    })
    var batchList = []
    batchData.map((item) => {
      if (item.year == selectedRouteData['year']) {
        batchList = item.list
        if (selectedRouteData['year'] !== this.data.selectedRouteData['year']) {
          selectedRouteData['batch'] = batchList.length>0?batchList[0].id:''
          wx.setStorageSync(filterRouteKey, selectedRouteData)
        }
      }
    })
    var spcgroupList = []
    spcgroupData.map((item) => {
      if (item.year == selectedRouteData['year']) {
        spcgroupList = item.list
        // console.log(batchList)
        if (selectedRouteData['year'] !== this.data.selectedRouteData['year']) {
          selectedRouteData['sgName'] = spcgroupList[0].id
          wx.setStorageSync(filterRouteKey, selectedRouteData)
        }
      }
    })
    selectedRouteDatas[2].items = list
    selectedRouteDatas[3].items = batchList
    selectedRouteDatas[4].items = spcgroupList
    selectedRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == selectedRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : ''
      if (item.key != 'provinceId') {
        selectedRouteData[item.key] = c.length > 0 ? c[0].title : ''
      }
    })
    this.setData({
      selectedRouteData,
      selectedRouteDatas,
      TabCur:0,
    })
    this.getScoreSpecial(selectedRouteData)
    this.getSpecialHistory(selectedRouteData)
  },

  // 获取专业批次
  async getSpecialBatch() {
    const {
      selectedRouteData,
      filterRouteKey,
      selectedRouteDatas,
      id
    } = this.data
    const params = {
      schoolId: id,
      provinceId: selectedRouteData.provinceId
    }
    const {
      result
    } = await specialBatch(params,two)
    if (result.length > 0) {
      result.sort((a, b) => {
        return b.year - a.year
      }) //倒序
      result.map((item) => {
        item.list.map((e, i) => {
          let obj = {
            id: e,
            title: e
          }
          item.list[i] = obj
        })
      })
      const {
        list
      } = result[0]
      selectedRouteData.batch = list[0].id
      selectedRouteDatas[3].items = list
    }

    selectedRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == selectedRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : item.title
    })
    this.setData({
      selectedRouteData,
      selectedRouteDatas
    })
    this.setData({
      selectedRouteData,
      selectedRouteDatas,
      batchData: result,
    })
    wx.setStorageSync(filterRouteKey, selectedRouteData)
    this.getSpecialSpcgroup()

  },
  // 获取专业分数线专业组
  async getSpecialSpcgroup() {
    const {
      selectedRouteData,
      filterRouteKey,
      selectedRouteDatas
    } = this.data
    // console.log(selectedRouteData.type)
    const params = {
      provinceId: selectedRouteData.provinceId,
      schoolId: this.data.id,
      type: selectedRouteData.type
    }
    const {
      result
    } = await specialSpcgroup(params,two)
    if (result.length <= 0) {
      selectedRouteData.sgName = ''
      selectedRouteDatas[4].items = []
      selectedRouteDatas[4].title = ''
    } else {
      result.sort((a, b) => {
        return b.year - a.year
      }) //倒序
      result.map((item) => {
        item.list.unshift('全部')
        item.list.map((e, i) => {
          let obj = {
            id: e,
            title: e
          }
          item.list[i] = obj
        })
      })
      const {
        list
      } = result[0]
      selectedRouteData.sgName = list[0].id
      selectedRouteDatas[4].items = list
    }
    selectedRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == selectedRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : item.title
    })
    this.setData({
      selectedRouteDatas,
      selectedRouteData,
      spcgroupData: result,
      TabCur:0,
    })
    wx.setStorageSync(filterRouteKey, selectedRouteData)
    this.getScoreSpecial(selectedRouteData)
    this.getSpecialHistory(selectedRouteData)
  },
  // 获取专业分数线 年份-类型
  async getSpecialCategory() {
    const {
      selectedRouteData,
      filterRouteKey,
      selectedRouteDatas,
      id
    } = this.data
    const params = {
      schoolId: id,
      provinceId: selectedRouteData.provinceId
    }
    const {
      result
    } = await specialCategory(params,two)

    result.sort((a, b) => {
      return b.year - a.year
    }) //倒序
    result.map((item) => {
      item.list=item.list.reverse()
      item.list.map((e, i) => {
        let obj = {
          id: e,
          title: e
        }
        item.list[i] = obj
      })
    })
    var yearArr = result.map((item) => {
      return {
        id: item.year,
        title: item.year
      }
    })
    if (result.length > 0) {
      const {
        list
      } = result[0]
      selectedRouteData.year = yearArr[0].id
      selectedRouteData.type = list[0].id
      const firstSelectSubjects=wx.getStorageSync('subjectInfo').firstSelectSubjects || ''
      if(firstSelectSubjects){
        list.map(e=>{
          if(e.id.indexOf(firstSelectSubjects)>-1){
             selectedRouteData['type']=e.id
          }
        })
      }
      selectedRouteDatas[1].items = yearArr
      selectedRouteDatas[2].items = list
    }
    selectedRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == selectedRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : item.title
    })
    this.setData({
      selectedRouteData,
      selectedRouteDatas
    })
    wx.setStorageSync(filterRouteKey, selectedRouteData)
    this.setData({
      categorydata: result
    })
    this.getSpecialBatch()
  },
  // 获取专业分数线
  async getScoreSpecial(selectData) {
    selectData.schoolId = this.data.id
    const {
      columns1
    } = this.data
    if (selectData.sgName === '全部') {
      selectData.sgName = ""
    }
    const {
      result
    } = await scoreSpecial(selectData,two)
    result.map(e => {
      if (!e.sgInfo) {
        e.sgInfo = e.spInfo
      }
    })
    let columnsList1 = []
    if (result.length > 0) {
      columnsList1 = columns1.filter((e) => {
        return result[0][e.prop]
      })
    } else {
      columnsList1 = columns1
    }
    // columnsList1.map((e) => {
    //   e.width = 650 / columnsList1.length
    // })
    this.setData({
      tabData1: result,
      columnsList1
    })
    this.selectComponent("#tabData2").hide('本省今年未发布该校分数信息')
  },
  // 获取往年专业分数线
  async getSpecialHistory(selectData){
    selectData.schoolId = this.data.id
    if (selectData.sgName === '全部') {
      selectData.sgName = ""
    }
    delete selectData.year
    const {
      result
    } = await specialHistory(selectData,two)
   const list=Object.keys(result).map(i=>{
      let max = Math.max.apply(Math,result[i].map(e => {
        return e.min
      }))
       return {
         title :i,
         list:result[i],
         max
       }
    })
    this.setData({
     historyList:list
    })
  },

  // 获取招生计划
  async onSelectChangedRoute2(e) {
    const {
      planRouteKey
    } = this.data
    wx.setStorageSync(planRouteKey, {
      ...e.detail
    });
    this.setData({
      pageNo: 1,
      tabData5: []
    })
    this.selectComponent("#tabData5").show()
    this.filterKeyFunc2()
  },
  // 获取招生计划
  getPlanList() {
    this.getPlanCategory()
    // this.getPlanBatch()
  },
  filterKeyFunc2() {
    const {
      planRouteKey
    } = this.data
    const planRouteData = wx.getStorageSync(planRouteKey)
    const {
      planRouteDatas,
      planCategorydata,
      planBatchData,
      planSpcgroupData
    } = this.data
    if (planRouteData['provinceId'] !== this.data.planRouteData['provinceId']) {
      this.setData({
        planRouteData
      })
      wx.setStorageSync(planRouteKey, planRouteData)
      this.getPlanList()
      return
    }
    if (planRouteData['type'] !== this.data.planRouteData['type']) {
      this.setData({
        planRouteData
      })
      wx.setStorageSync(planRouteKey, planRouteData)
      this.getPlanSpcgroup()
      return
    }
    var list = []
    planCategorydata.map((item) => {
      if (item.year == planRouteData['year']) {
        list = item.list
        if (planRouteData['year'] !== this.data.planRouteData['year']) {
          planRouteData['type'] = list[0].id
          const firstSelectSubjects=wx.getStorageSync('subjectInfo').firstSelectSubjects || ''
          if(firstSelectSubjects){
            list.map(e=>{
              if(e.id.indexOf(firstSelectSubjects)>-1){
                planRouteData['type']=e.id
              }
            })
          }
          wx.setStorageSync(planRouteKey, planRouteData)
        }
      }
    })
    var batchList = []
    planBatchData.map((item) => {
      if (item.year == planRouteData['year']) {
        batchList = item.list
        if (planRouteData['year'] !== this.data.planRouteData['year']) {
          planRouteData['localBatchName'] = batchList[0].id
          wx.setStorageSync(planRouteKey, planRouteData)
        }
      }
    })
    var spcgroupList = []
    planSpcgroupData.map((item) => {
      if (item.year == planRouteData['year']) {
        spcgroupList = item.list
        // console.log(batchList)
        if (planRouteData['year'] !== this.data.planRouteData['year']) {
          planRouteData['sgName'] = spcgroupList[0].id
          wx.setStorageSync(planRouteKey, planRouteData)
        }
      }
    })
    planRouteDatas[2].items = list
    planRouteDatas[3].items = batchList
    planRouteDatas[4].items = spcgroupList
    planRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == planRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : ''
      if (item.key != 'provinceId') {
        planRouteData[item.key] = c.length > 0 ? c[0].title : ''
      }
    })
    this.setData({
      planRouteDatas,
      planRouteData
    })
    wx.setStorageSync(planRouteKey, planRouteData)
    this.onLoadFunc()
    this.getPlanHistory()
  },
  onLoadFunc() {
    this.setData({
      pageNo: 1,
      tabData5: []
    })
    this.getPlanPage()
  },
  // 获取专业批次
  async getPlanBatch() {
    const {
      planRouteData,
      planRouteKey,
      planRouteDatas
    } = this.data
    const params = {
      provinceId: planRouteData.provinceId,
      schoolId: this.data.id
    }
    const {
      result
    } = await planBatch(params,two)
    if (result.length > 0) {
      result.sort((a, b) => {
        return b.year - a.year
      }) //倒序
      result.map((item) => {
        item.list.map((e, i) => {
          let obj = {
            id: e,
            title: e
          }
          item.list[i] = obj
        })
      })
      const {
        list
      } = result[0]
      planRouteData.localBatchName = list[0].id
      planRouteDatas[3].items = list
    }
    planRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == planRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : item.title
    })
    this.setData({
      planRouteDatas,
      planRouteData
    })
    wx.setStorageSync(planRouteKey, planRouteData)
    this.setData({
      planBatchData: result,
    })
    this.getPlanSpcgroup()
  },
  // 获取招生计划专业组
  async getPlanSpcgroup() {
    const {
      planRouteData,
      planRouteKey,
      planRouteDatas
    } = this.data
    const params = {
      provinceId: planRouteData.provinceId,
      schoolId: this.data.id,
      type: planRouteData.type,
    }
    const {
      result
    } = await planSpcgroup(params,two)
    if (result.length <= 0) {
      planRouteData.sgName = ''
      planRouteDatas[4].items = []
      planRouteDatas[4].title = ''
    } else {
      result.sort((a, b) => {
        return b.year - a.year
      }) //倒序
      result.map((item) => {
        item.list.unshift('全部')
        item.list.map((e, i) => {
          let obj = {
            id: e,
            title: e
          }
          item.list[i] = obj
        })
      })
      const {
        list
      } = result[0]
      planRouteData.sgName = list[0].id
      planRouteDatas[4].items = list
    }
    planRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == planRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : item.title
    })
    this.setData({
      planRouteDatas,
      planRouteData,
      planSpcgroupData: result,
    })
    wx.setStorageSync(planRouteKey, planRouteData)
    this.onLoadFunc()
    this.getPlanHistory()
  },
  // 获取招生计划 年份-类型
  async getPlanCategory() {
    const {
      planRouteData,
      planRouteKey,
      planRouteDatas
    } = this.data
    const params = {
      provinceId: planRouteData.provinceId,
      schoolId: this.data.id
    }
    const {
      result
    } = await planCategory(params,two)
    result.sort((a, b) => {
      return b.year - a.year
    }) //倒序
    if (result.length > 0) {
      result.map((item) => {
        item.list=item.list.reverse()
        item.list.map((e, i) => {
          let obj = {
            id: e,
            title: e
          }
          item.list[i] = obj
        })
      })
      var yearArr = result.map((item) => {
        return {
          id: item.year,
          title: item.year
        }
      })

      const {
        list
      } = result[0]
      planRouteData.year = yearArr[0].id
      planRouteData.type = list[0].id
      const firstSelectSubjects=wx.getStorageSync('subjectInfo').firstSelectSubjects || ''
      if(firstSelectSubjects){
        list.map(e=>{
          if(e.id.indexOf(firstSelectSubjects)>-1){
            planRouteData['type']=e.id
          }
        })
      }
      planRouteDatas[1].items = yearArr
      planRouteDatas[2].items = list
    }

    planRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == planRouteData[item.key]
      })
      item.title = c.length > 0 ? c[0].title : item.title
    })
    this.setData({
      planRouteDatas,
      planRouteData
    })
    wx.setStorageSync(planRouteKey, planRouteData)
    this.setData({
      planCategorydata: result,
    })
    this.getPlanBatch()
  },
  // 获取招生计划列表
  async getPlanPage() {
    const {
      pageSize,
      id,
      pageNo,
      columns5,
      planRouteData
    } = this.data
    let {
      localBatchName,
      type,
      provinceId,
      year,
      sgName
    } = planRouteData
    const params = {
      pageSize,
      pageNo,
      schoolId: id,
      localBatchName,
      type,
      provinceId,
      year,
      sgName: sgName == '全部' ? '' : sgName
    }

    const {
      result
    } = await planPage(params,two)
    result.records.map(e => {
      if (!e.sgInfo || e.sgInfo == '-') {
        e.sgInfo = e.spInfo
      }
    })
    let columnsList5 = []
    if (result.total > 0) {
      columnsList5 = columns5.filter((e) => {
        if (result.records[0][e.prop]) {
          return result.records[0][e.prop]
        }
      })
    } else {
      columnsList5 = columns5
    }
    // columnsList5.map((e) => {
    //   e.width = 650 / columnsList5.length
    // })
    this.setData({
      tabData5: this.data.tabData5.concat(result.records),
      pageNo: pageNo + 1,
      columnsList5,
      total: result.total,
    })
    this.selectComponent("#tabData5").hide('本省今年未发布该校招生计划')
  },
  async getPlanHistory(){
      const {
        id,
        columns5,
        planRouteData
      } = this.data
      let {
        localBatchName,
        type,
        provinceId,
        year,
        sgName
      } = planRouteData
      const params = {
        schoolId: id,
        localBatchName,
        type,
        provinceId,
        // year,
        sgName: sgName == '全部' ? '' : sgName
      }
      const {
        result
      } = await planHistory(params)
      const list=Object.keys(result).map(i=>{
         return {
           title :i,
           list:result[i]
         }
      })
      this.setData({
        planHistory:list
      })
  },
  onReachBottom() {
    const {
      tabData5,
      pageSize,
      total,
      luquList,
      luquListTotal,
      currentIndex,
      isVip
    } = this.data
    if (currentIndex == 2) {
      const count = tabData5.length
      if (count == total || count == 0) return
      this.getPlanPage()
      return
    }
    if (currentIndex == 4) {
      const count1 = luquList.length
      // console.log(count1)
      // console.log(luquListTotal)
      if (count1 == luquListTotal || count1 == 0 || !isVip) return
      //  this.getEnrollmentList()
    }

  },


  // 获取招生快讯
  async getSchoolNewsPage() {
    const {
      id
    } = this.data
    const params = {
      pageNo: 1,
      pageSize: 3,
      schoolId: id
    }
    const {
      result
    } = await schoolNewsPage(params)
    this.setData({
      admitList: result.records
    })
  },
  // 获取开设专业
  async getOpenmajor() {
    const {
      id
    } = this.data
    const {
      result
    } = await openmajor(id)
    this.setData({
      majorList: result,
    })
  },

  // 获取毕业生就业单位性质
  async getEmploymentunittype(schoolId) {
    const {
      list1
    } = this.data
    if (list1.length > 0) return
    const {
      result
    } = await employmentunittype(schoolId)
    const list = result.filter((item) => {
      return item.proportion > 0
    })
    let max = Math.max.apply(Math, list.map(e => {
      return e.proportion
    }))
    this.setData({
      list1: list,
      max
    })
  },
  // 获取毕业生就业单位
  async getEmploymentunit(schoolId) {
    const {
      tabData3
    } = this.data
    if (tabData3.length > 0) return
    const {
      result
    } = await employmentunit(schoolId)
    this.setData({
      tabData3: result,
    })
  },

  makePhone(e) {
    const {
      phone
    } = e.currentTarget.dataset
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  // 复制链接
  textPaste(e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success(res) {
        wx.showToast({
          title: '地址复制成功',
          icon: 'none'
        })
      }
    })
  },
  // 获取详情数据
  async getDetail() {
    const {
      id
    } = this.data
    const {
      result
    } = await schoolDetail(id)
    result.level=returnLabel(result) || []
    // result.schoolSpecialtyVoList.map((item) => {
    //    item['show'] = false
    // })
    var aSchoolSpecialtyVoList = []
    result.doubleFirstClassConstructionDisciplines && result.doubleFirstClassConstructionDisciplines.split(';').map(e => {
      let obj = {}
      obj.id = e.split(':')[0]
      obj.specialtyName = e.split(':')[1]
      if (obj.id) {
        aSchoolSpecialtyVoList.push(obj)
      }
    })
    result.eduLevel = result.eduLevelName && result.eduLevelName.indexOf('普通本科') > -1 ? 1 : 2
    result.listPicUrl = result.listPicUrl.replace(/\s*/g, "");
    var picList = result.listPicUrl.split(',')
    var reg = /[,，]/g;
    result.phone = result.phone.replace(reg, "\n");
    // result['provinceCity'] = this.filterProvinceCity(result.schoolAddress, result.provincesName)
    this.setData({
      details: result,
      picList: picList,
      aSchoolSpecialtyVoList,
    })
    const that = this
    const query = wx.createSelectorQuery();
    query.selectAll('.item_desc_txt').fields({
      size: true,
    }).exec(function (res) {
      // console.log(res)
      let lineHeight = 20; //固定高度值 单位：PX
      if (res[0][0].height / lineHeight > 8) {
        that.setData({
          seeMore: true,
        })
      }

    })
  },
  openModal() {
    this.setData({
      visible: true
    })
  },
  filterProvinceCity(str, province) {
    const provinceIndex = str.lastIndexOf('省')
    const cityIndex = str.lastIndexOf('市')
    const regionIndex = str.lastIndexOf('区')
    var name = ''
    const provinceList = ['广西', '内蒙古', '西藏', '宁夏', '新疆']
    if (str.indexOf('北京') > -1 || str.indexOf('上海') > -1 || str.indexOf('重庆') > -1 || str.indexOf('天津') > -1) {

      name = province + '市·' + str.substring(cityIndex + 1, regionIndex + 1)
    } else if (str.indexOf('广西') > -1 || str.indexOf('内蒙古') > -1 || str.indexOf('西藏') > -1 || str.indexOf('宁夏') > -1 || str.indexOf('新疆') > -1) {
      provinceList.map((item) => {
        if (str.indexOf(item) > -1) {
          const index = str.lastIndexOf(item)
          const lastSpecialIndex = str.lastIndexOf('自治区')
          const lastCityIndex = str.lastIndexOf('市')
          name = province + '·' + str.substring(lastSpecialIndex > -1 ? (lastSpecialIndex + 3) : (index + item.length), lastCityIndex + 1)
        }
      })
    } else {
      name = province + '省·' + str.substring(provinceIndex + 1, cityIndex + 1)
    }
    return name
  },
  // filterProvinceCity(str, province){
  //   var newStr=[]
  //   const list=city.list
  //   list.map((item)=>{
  //     if(str.indexOf(item.name)>-1){
  //       newStr.push(item.name)
  //       item.city.map((city)=>{
  //         if(str.indexOf(city.name)>-1){
  //           newStr.push(city.name)
  //           city.area.map((area)=>{
  //             if(str.indexOf(area)>-1){
  //               newStr.push(area)
  //             }
  //           })
  //         }
  //       })
  //     }
  //   })

  //   let value=''
  //   if (province.indexOf('北京') > -1 || province.indexOf('上海') > -1 || province.indexOf('重庆') > -1 || province.indexOf('天津') > -1){
  //     value=newStr[1]+(newStr[2]==undefined?'':'·'+newStr[2]||'')
  //   }else{
  //     value=newStr[0]+'·'+newStr[1]

  //   }
  //   return value
  // },
  //预览
  previewImage(e) {
    var imgList = [];
    for (let i = 0; i < this.data.picList.length; i++) {
      imgList.push(this.data.picList[i]);
    }
    wx.previewImage({
      current: e.currentTarget.dataset.src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // this.ecComponent = this.selectComponent('#mychart-dom-area');
    // this.initChart();
  },
  async initChart() {
    const {
      id,
      pieData
    } = this.data
    const {
      result
    } = await signedplace(id)
    if (pieData.length > 0) return
    const data = result.map(e => {
      return {
        name: e.province,
        value: e.rate
      }
    })
    data.sort((a, b) => b.value - a.value)
    if (data.length == 0) {
      return
    }
    this.setData({
      pieData: data
    })
    this.ecComponent = this.selectComponent('#mychart-dom-area');
    this.ecComponent.init((canvas, width, height, dpr) => {
      const chart = echarts.init(canvas, null, {
        width: width,
        height: height,
        devicePixelRatio: dpr, // new
      });
      setPieoption(chart, data);
      this.chart = chart;
      return chart;
    });

  },

  onShareAppMessage: function (e) {
    const {
      details
    } = this.data
    if(e.from==='button'){
       return {
       title: details.name,
        path: `/pages/school/detail/index?id=${details.id}&name=${details.name}&spreadUserId=${wx.getStorageSync('userInfo').id}`,
        imageUrl:'https://ehsimg.oss-cn-beijing.aliyuncs.com/images/static/users/shareImg.jpg'
        }
    }
    return {
      title: details.name,
      path: `/pages/school/detail/index?id=${details.id}&name=${details.name}`,
      imageUrl:'https://ehsimg.oss-cn-beijing.aliyuncs.com/images/static/users/shareImg.jpg'
    }
   
   
  },
  previewImg(e) {
    getApp().globalData.preview = false;
    var src = e.currentTarget.dataset.src
    var str = this.data.details.newImgList
    //图片预览
    wx.previewImage({
      current: src,
      // 当前显示图片的http链接
      urls: str // 需要预览的图片http链接列表
    });
  },
  more(e) {
    wx.navigateTo({
      url: '/pages/article/list/index?id=' + this.data.id,
    })
  },
  linkClick() {
    // wx.navigateTo({
    //   url: '/pages/web/index?url=' + this.data.details.officialWebsite,
    // })
  },
  goto(e) {
    const {
      url,
      pdf
    } = e.currentTarget.dataset
    if (pdf) {
      wx.showLoading({
        title: '加载中',
      })
      wx.downloadFile({
        url: pdf,
        success: function (res) {
          const filePath = res.tempFilePath
          wx.openDocument({
            filePath: filePath,
            fileType: 'pdf',
            showMenu: true,
            success: function (res) {
              wx.hideLoading()
            }
          })
        }
      })
      return
    }
      this.setData({
        volunteerShow:false
      })
    wx.navigateTo({
      url,
    })
  },

  // 分校 院系
  async go(e) {
    const {
      id
    } = e.currentTarget.dataset
    const {
      result
    } = await schoolBranchDetail(id)
    wx.navigateTo({
      url: `/pages/article/rich-text/index?content=` + encodeURIComponent(result.content) + '&name=' + result.yxName,
    })
  },
  async getSchoolBranch() {
    const {
      id
    } = this.data
    const params = {
      pageNo: 1,
      pageSize: 999,
      schoolId: id
    }
    const {
      result
    } = await schoolBranch(params)
    const branchList = this.getBranchList(result.records)
    // console.log(result.total)
    this.setData({
      branchList,
      branchTotal: result.total
    })
  },
  getBranchList(data) {
    let map = {}
    data.forEach(item => {
      map[item.fxName] = {
        fxName: item.fxName,
        child: []
      }
    })
    data.forEach((item) => {
      if (item.fxName == map[item.fxName].fxName) {
        map[item.fxName].child.push(item)
      }
    })
    return map
  },

  async collect(e) {
    const {
      details
    } = this.data
    const {
      id,
      isCollection
    } = details
    details.isCollection = !isCollection
    const {
      result
    } = await schoolAdd(id)
    if (isCollection) {
      wx.showToast({
        title: '取消收藏',
        icon: 'none'
      })
    } else {
      wx.showToast({
        title: '收藏成功',
        icon: 'none'
      })
    }
    this.setData({
      details
    })
  }

})
